<template>
      <div>
        <div class="layout-padding-auto layout-padding-view">
            <!--  标题行    -->
            <el-row :gutter="20" style="margin: 0px -50px 20px 5px;">
                <el-col :span="21" v-if="route.query.state=='0'"><h1 class="my-heading">创建学习任务</h1></el-col>
                <el-col :span="20"  v-else-if="route.query.state=='1'"><h1 class="my-heading">编辑学习任务</h1></el-col>
                <el-col :span="1.5"><el-button :disabled="isButtonDisabled" @click="uploadSysFileSubmit">保存</el-button></el-col>
<!--                <el-col :span="1.5"><el-button @click="goBack">返回</el-button></el-col>-->
            </el-row>
            <!--    条件行   -->
            <el-row v-show="showSearch">
                <el-form :model="form" ref="dataFormRef" :rules="dataRules" :inline="true" @keyup.enter="getDataList">
                    <el-row :gutter="24">
                        <el-col :span="8" class="mb20">
                            <el-form-item label="任务名称" prop="taskName">
                                <el-input :disabled="isDisabled" placeholder="请输入任务名称" v-model="form.taskName" clearable />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item  label="参考组织" prop="orgId">
                                <el-cascader :disabled="isDisabled"   v-model="form.orgId" ref="cascaderAddr1" @visible-change="handleVisibleChange" style="width: 260px" placeholder="请选择标签" @change="handleCascaderChange1"
                                :props="{ value: 'id', label: 'name', children: 'children',checkStrictly: true }" :options="options1" clearable filterable>
                                </el-cascader>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="参考岗位" prop="postName">
                                <el-select  :disabled="isDisabled" @change="getItem1" v-model="form.postName" multiple filterable collapse-tags collapse-tags-tooltip  placeholder="请选择" style="width: 240px">
                                    <el-option v-for="item in postList" :key="item.postsString" :label="item.postName" :value="item.postName"/>
                                </el-select>
                            </el-form-item>
                        </el-col>
                         <el-col :span="8" class="mb20">
                            <el-form-item label="参考人员" prop="persons">
                                <el-select :disabled="isDisabled" @change="getItem2" v-model="persons" multiple filterable collapse-tags collapse-tags-tooltip  placeholder="请选择" style="width: 240px">
                                    <el-checkbox v-model="checked" @change='selectAll' style="margin-left: 20px">全选</el-checkbox>
                                    <!--<el-option v-for="item in personList" :key="item.username" :label="item.name+'-'+item.postName" :value="item.username"/>-->
                                    <el-option v-for="item in personList" :key="item.username" :label="item.name ? (item.name + '-' + (item.postName || '')) : ''" :value="item.username"/>
                                </el-select>
                         </el-form-item>
                         </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="专业名称" prop="zymcName">
                                <el-select :disabled="isDisabled" @change="getitem3" v-model="form.zymcName" filterable clearable multiple collapse-tags collapse-tags-tooltip  placeholder="请选择" style="width: 240px">
                                    <el-option v-for="item in options2"  :key="item.zymcId" :label="item.zymcName" :value="item.zymcName"/>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="关键点" prop="keyPoint">
                                <el-select :disabled="isDisabled" @change="getitem4" v-model="form.keyPoint" filterable multiple clearable collapse-tags collapse-tags-tooltip placeholder="请选择" style="width: 240px">
                                    <el-option v-for="item in keypointsListData" :key="item.keyId" :label="item.zymcName+'-'+item.keyPoint" :value="item.keyPoint"/>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="考试名称" prop="examName">
                                <el-input disabled  v-model="form.examName" clearable />
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="是否关联考试" prop="isRelateExam">
                                <el-switch v-model="form.isRelateExam" :active-value="1" :inactive-value="0" @change="changeexam"/>
                                <el-button type="text" style="margin-left:20px"  :visible.sync="dialogVisible2"  v-if="!dataList.examId && !form.examId && !form.examName"    :disabled="!form.isRelateExam"   @click="testquestions(0,dataList.examId)"> 新建考试</el-button>
                                <el-button type="text" style="margin-left:20px" :visible.sync="dialogVisible2" v-else-if="dataList.examId !== null && form.examId !== null"  :disabled="!form.isRelateExam"   @click="testquestions(1,dataList.examId)"> 编辑考试</el-button>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20" v-if="form.isRelateExam === 1">
                            <el-form-item label="是否完成学习资料后才能考试" prop="isExamAfterData">
                                <el-switch v-model="form.isExamAfterData"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="是否限时" prop="isTimeLimit" :rules="[{ required: true, message: '请选择是否限时',trigger: 'change',}]">
                                <el-switch v-model="form.isTimeLimit" :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20" v-if="form.isTimeLimit === 1">
                            <el-form-item label="开始时间" prop="startTime" :rules="[{ required: true, message: '请选择开始时间',trigger: 'change',}]">
                                <el-date-picker  v-model="form.startTime" type="datetime" placeholder="选择日期时间" @change="handleEndTimeChange"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20" v-if="form.isTimeLimit === 1">
                            <el-form-item label="结束时间" prop="endTime" :rules="[{ required: true, message: '请选择结束时间',trigger: 'change',}]">
                                <el-date-picker  v-model="form.endTime" type="datetime" placeholder="选择日期时间"  @change="handleEndTimeChange1"></el-date-picker>
                             </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20" v-if="form.isTimeLimit === 1">
                            <el-text style="color: red">注:开始时间必须大于当前时间,结束时间必须大于开始时间30分钟以上</el-text>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="是否学完本课题才能看下课题" prop="isTopicEnd">
                                <el-switch v-model="form.isTopicEnd"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" class="mb20">
                            <el-form-item label="是否执行‘531’行动计划" prop="isExcutePlan">
                                <el-switch v-model="form.isExcutePlan"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="异常提醒天数" prop="abnormalDays">
                                <el-input-number v-model="form.abnormalDays" :min="1" :max="10" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="是否颁发证书" prop="isIssuingCertificates">
                                <el-switch  v-model="form.isIssuingCertificates"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20" v-if="form.isIssuingCertificates === 1">
                            <el-form-item label="获得证书人员是否需要学习" prop="gainCertificateIsStudy">
                                <el-switch v-model="form.gainCertificateIsStudy"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" class="mb20"  v-if="form.isIssuingCertificates === 1">
                            <el-form-item label="证书名称" prop="certificateId">
                                <el-select v-model="form.certificateId" clearable placeholder="请选择证书名称" style="width: 240px">
                                    <el-option v-for="item in certificateList" :key="item.certificateId" :label="item.certificate" :value="item.certificateId"/>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20"  v-if="form.isIssuingCertificates === 1">
                            <div class="option">
                                <el-form-item prop="issuanceConditions"  class="answer">
                                  <el-radio-group v-model="form.issuanceConditions">
                                    <el-radio  :label="1" v-if="form.isRelateExam == 0">
                                        <el-text class="input3">学习进度到</el-text>
                                            <el-input-number v-model="form.issuanceConditionsProgress1" :min="1" :max="100" style="width:50%"/>
                                        <el-text class="input3">%及以上</el-text>
                                    </el-radio>
                                    <el-radio :label="3" style="margin-top:15px" v-if="form.isRelateExam == 1">
                                      <el-text class="input3">考试在</el-text>
                                      <el-input-number v-model="form.issuanceConditionsScore3" :min="1" :max="100" style="width:50%"/>
                                      <el-text class="input3">分以上</el-text>
                                    </el-radio>
                                    <el-radio :label="2" style="margin-top:15px" v-if="form.isRelateExam == 1">
                                        <el-text class="input3">学习进度到</el-text>
                                        <el-input-number v-model="form.issuanceConditionsProgress2" :min="1" :max="100" style="width:30%"/>
                                        <el-text class="input3">%及以上</el-text>
                                        <el-text class="input3">且考试在</el-text>
                                        <el-input-number v-model="form.issuanceConditionsScore2" :min="1" :max="100" style="width:30%"/>
                                        <el-text class="input3">分以上</el-text>
                                    </el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="24" class="mb20">
                            <el-form-item label="选择学习资料" :rules="[{ required: true, message: '请选择学习资料',trigger: 'change',}]">
                                <el-button type="primary" :visible.sync="dialogVisible" :disabled="!isOrgSelected || !isPostSelected || !isMajorSelected || !hasKeyPointsSelected"    @click="association">去选择</el-button>
                            </el-form-item>
                            <el-text></el-text>
                            <div style="color: red;font-size:18px">注:选择资料之前必须选择组织/岗位/专业名称/关键点!!</div>
                            <div style="color: red;font-size:18px">注:包含考试的需要先创建考试才能选择资料!!</div>
                            <el-table :data="form.xxrwTaskRelateDateList" style="margin-top: 20px;">
                                <el-table-column prop="dataName" label="资料名称"/>
                                <el-table-column prop="studyGroup" label="参与组织" width="300"/>
                                <el-table-column prop="postName" label="参与岗位"/>
                                <el-table-column prop="zymcName" label="专业名称"/>
                                <el-table-column prop="keyPoints" label="关键点"/>
                                <el-table-column prop="dataType" label="资料类型"/>
                                <el-table-column label="操作">
                                    <template #default="scope">
                                        <el-button text type="primary" @click="handleTest(scope.row)">试题数量</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-col>
                    </el-row>
                </el-form>
            </el-row>
        </div>
        <!-- 新建试题 -->
        <el-dialog v-model="dialogVisible2" title="试题" :before-close="handleClose"
         style="width: 100%; display: flex; flex-direction: column;">
                <el-row :gutter="20" style="margin: 0px -50px 20px 5px;">
                    <el-col :span="21" v-if="route.query.state1=='0'"><h1 class="my-heading">创建考试</h1></el-col>
                    <el-col :span="21"  v-else-if="route.query.state1=='1'"><h1 class="my-heading">编辑考试</h1></el-col>
                </el-row>
                <el-form ref="dataFormRef1" :model="form1" :rules="dataRules1" label-width="120px" >
                    <el-row :gutter="24">
                        <el-col :span="8" class="mb20">
                            <el-form-item label="考试名称" prop="examName">
                                <el-input v-model="form1.examName" placeholder="请输入考试名称"  :disabled="started"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8" class="mb20">
                            <el-form-item  label="参考组织" prop="groupIds">
                                <el-cascader disabled v-model="form1.groupIds" ref="cascaderAddr1" style="width: 420px" placeholder="请选择标签"  @change="handleCascaderChange1"
                                 :props="{ value: 'id', label: 'name', children: 'children',checkStrictly: true }" :options="options1" clearable filterable @visible-change="handleVisibleChange">
                                </el-cascader>
                            </el-form-item>
                            <el-form-item label="参考岗位" prop="postNames">
                                <el-select disabled   @change="getItem1" v-model="form1.postNames" multiple collapse-tags collapse-tags-tooltip placeholder="请选择" style="width: 240px">
                                    <el-option v-for="item in postList" :key="item.postIds" :label="item.postName" :value="item.postName"/>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="参考人员" prop="personName">
                                <el-select  disabled @change="getItem2" v-model="persons2"  multiple filterable collapse-tags collapse-tags-tooltip  placeholder="请选择" style="width: 240px">
                                    <el-checkbox v-model="checked" @change='selectAll1' style="margin-left: 20px">全选</el-checkbox>
                                    <el-option v-for="item in personList" :key="item.username" :label="item.name+'-'+item.postName" :value="item.username"/>
                                </el-select>
                            </el-form-item>
<!--                            <el-form-item label="参考人员" prop="personName" v-if="route.query.state1=='0'">-->
<!--                                <el-select disabled v-model="form1.personName" placeholder="请选择" style="width: 240px">-->
<!--                                    <el-option v-for="item in options" :key="item.personName" :label="item.personName" :value="item.personName"/>-->
<!--                                </el-select>-->
<!--                            </el-form-item>-->
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="选择试卷" prop="examPaperName">
                                <el-input v-model="form1.examPaperName" placeholder="请输入" disabled/>
                                <el-button type="primary" v-if="form1.examPaperName==''"  text @click="formDialogRef.openDialog(form1.groupIds,form1.postIds,form1.examPaperId,0)">新建试卷</el-button>
                                <el-button type="primary" v-if="form1.examPaperName!==''"  text @click="formDialogRef.openDialog(form1.groupIds,form1.postIds,form1.examPaperId,1,form1.examId)">编辑试卷</el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="12" class="mb20">
                            <el-form-item label="考试说明" prop="examRemark">
                                <el-input  type="textarea" v-model="form1.examRemark" placeholder="请输入"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8" class="mb20">
                            <el-form-item label="考试时长" prop="examTime">
                                <el-input-number v-model="form1.examTime" :min="30" :max="120" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="2" style="margin-left: -12px;margin-top:5px">
                            <el-text class="input3">分钟</el-text>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="6" class="mb20">
                            <el-form-item label="提前交卷" prop="submitInadvanceState">
                                <el-switch v-model="form1.submitInadvanceState"  :active-value="0" :inactive-value="1"/>
                            </el-form-item>`
                        </el-col>
                    </el-row>
                    <el-row :gutter="24" v-if="form1.submitInadvanceState === 0">
                        <el-col :span="2" class="mb20">
                            <el-form-item label="允许交卷时间：" style="margin-left: 12px"></el-form-item>
                        </el-col>
                        <el-col :span="8" class="mb20">
                            <el-form-item label="考试开始后" prop="allowStartTime">
                                <el-input-number v-model="form1.allowStartTime" :min="1" :max="60" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="2" style="margin-left: -12px;margin-top:5px">
                            <el-text class="input3">分钟</el-text>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="5" class="mb20"  style="display: none">
                            <el-form-item label="错题优先" prop="wrongQuestionFirstState">
                                <el-switch v-model="form1.wrongQuestionFirstState"  :active-value="1" :inactive-value="0"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8" class="mb20">
                            <el-form-item label="考试结束前" prop="sendRemindTime">
                                <el-input-number v-model="form1.sendRemindTime" :min="1" :max="60"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="margin-left: -12px;;margin-top:5px">
                            <el-text class="input3">分钟发送提醒(加默认值)</el-text>
                        </el-col>
                    </el-row>
                    <div class="line"></div>
                    <el-row :gutter="24">
                        <el-col :span="10">
                            <el-text style="line-height: 50px; margin-left: 5px; font-size: 16px;">完成试卷</el-text>
                            <el-form-item label="及格分数:" label-width="100px" style="display: flex; align-items: center;">
                                <div style="display: flex; flex: 1;">
                                    <el-text>{{leftBoundary1}}分</el-text>
                                </div>
                            </el-form-item>
                            <el-form-item>
                                <el-col :span="6">
                                    <el-input-number v-model="leftBoundary0" :min="0" :max="100" class="input5" disabled/>
                                </el-col>
                                <el-text style="font-weight: bold;"><=得分<</el-text>
                                <el-col :span="6">
                                    <el-input-number v-model="leftBoundary1" :min="1" :max="100" class="input5" disabled/>
                                </el-col>
                                <el-text class="content1">评价:</el-text>
                                <el-col :span="4">
                                    <el-input v-model="scoreLevel0" placeholder="" class="input4"/>
                                </el-col>
                                    <el-text>(不及格分数段)</el-text>
                            </el-form-item>
                            <el-form-item>
                                <el-col :span="6">
                                  <el-input-number v-model="leftBoundary1"  :min="0" :max="100" class="input5" @change="changeMark"/>
                                </el-col>
                                <el-text style="font-weight: bold"><=得分<</el-text>
                                <el-col :span="6">
                                  <el-input-number v-model="leftBoundary2" :min="1" :max="100" class="input5" disabled/>
                                </el-col>
                                <el-text class="content1">评价:</el-text>
                                <el-col :span="4">
                                  <el-input v-model="scoreLevel1" placeholder="" class="input4"/>
                                </el-col>
                            </el-form-item>
                            <el-form-item>
                                <el-col :span="6">
                                    <el-input-number v-model="leftBoundary2"  :min="0" :max="100" class="input5" @change="changeMark1"/>
                                </el-col>
                                <el-text style="font-weight: bold"><=得分<</el-text>
                                <el-col :span="6">
                                  <el-input-number v-model="leftBoundary3" :min="1" :max="100" class="input5" disabled/>
                                </el-col>
                                <el-text class="content1">评价:</el-text>
                                <el-col :span="4">
                                  <el-input v-model="scoreLevel2" placeholder="" class="input4"/>
                                </el-col>
                            </el-form-item>
                            <el-form-item>
                                <el-col :span="6">
                                  <el-input-number v-model="leftBoundary3"  :min="0" :max="100" class="input5" @change="changeMark2"/>
                                </el-col>
                                <el-text style="font-weight: bold"><=得分<</el-text>
                                <el-col :span="6">
                                   <el-input-number v-model="rightBoundary3" :min="1" :max="100" class="input5" disabled/>
                                </el-col>
                                <el-text class="content1">评价:</el-text>
                                <el-col :span="4">
                                   <el-input v-model="scoreLevel3" placeholder="" class="input4"/>
                                </el-col>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="11" class="mb20" style="margin-left: 0px">
                            <el-text class="content">试题显示</el-text>
                            <el-form-item style="margin-left: 50px" label="试题顺序：" prop="questionOrder">
                                <el-radio-group v-model="form1.questionOrder">
                                    <el-radio :label="0">顺序</el-radio>
                                    <el-radio :label="1">随机</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item style="margin-left: 50px" label="选项顺序：" prop="optionsOrder">
                                <el-radio-group v-model="form1.optionsOrder">
                                    <el-radio :label="0">顺序</el-radio>
                                    <el-radio :label="1">随机</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <div><el-text style="margin-left: 100px;font-size: 14px;color: #817B7B;">打乱顺序可以防止考生之间传递答案</el-text></div>
                            <el-form-item style="margin-top: 30px"  label="结束页面" prop="finishExamState">
                                <el-radio-group v-model="form1.finishExamState">
                                    <el-radio :label="0">不显示成绩</el-radio>
                                    <el-radio :label="1">显示成绩、答案详情、答案解析</el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="24" class="mb20">
                            <div style="text-align:center">
                                <el-button type="primary" :visible.sync="dialogVisible2" @click="onSubmit" :disabled="loading" >保存考试</el-button>
                                <el-button type="danger"@click="dialogVisible2 = false">取消</el-button>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
            <el-dialog v-model="innerVisible" width="400" style="font-weight: bold" title="提醒" append-to-body center>
                <span style="font-size: 16px;margin-left: 30px">考试区间需大于考试时长,请重新设定</span>
            </el-dialog>
            <!-- 编辑、新增  -->
            <form-dialog ref="formDialogRef" @refresh="getDataList(false)" @parentsEmit="pEmitData"/>
        </el-dialog>
        <!-- 选择资料 -->
        <el-dialog v-model="dialogVisible" title="选择资料" :before-close="handleClose" width="100%">
           <span style="font-weight:700">资料库</span>
            <el-row v-show="showSearch">
                <el-form :model="queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
                    <el-form-item label="资料名称" prop="dataName" >
                        <el-input v-model="queryForm.dataName" clearable placeholder="请输入资料名称"/>
                    </el-form-item>
<!--                    <el-form-item  label="学习组织" prop="studyGroup">-->
<!--                        <el-tree-select disabled v-model="queryForm.studyGroup" :data="options1" :props="{ value: 'id', label: 'name', children: 'children' }"-->
<!--                        @current-change="treeHandleChange" clearable check-strictly :render-after-expand="false" placeholder="请选择"/>-->
<!--                    </el-form-item>-->
                    <el-form-item label="学习岗位" prop="studyPost">
                        <el-select disabled  v-model="queryForm.studyPost" filterable multiple clearable collapse-tags collapse-tags-tooltip :max-collapse-tags="3" placeholder="请选择" style="width: 90%;">
                            <el-option v-for="item in postList" :key="item.postId" :label="item.postName" :value="item.postName"/>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="专业名称" prop="majorNames">
                        <el-select disabled  @change="getitem3" v-model="queryForm.majorNames" filterable clearable multiple collapse-tags collapse-tags-tooltip :max-collapse-tags="3" placeholder="请选择" style="width: 240px">
                            <el-option v-for="item in options2"  :key="item.zymcId" :label="item.zymcName" :value="item.zymcName"/>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="关键点" prop="keyPoint">
                        <el-select disabled  v-model="queryForm.keyPoint"  multiple collapse-tags collapse-tags-tooltip :max-collapse-tags="3" placeholder="请选择" style="width: 240px">
                            <el-option v-for="item in keypointsListData" :key="item.keyId" :label="item.zymcName ? (item.zymcName + '-' + (item.keyPoint || '')) : ''" :value="item.keyId"/>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button icon="search" type="primary" @click="queryList">查询</el-button>
                    </el-form-item>
                </el-form>
            </el-row>
            <el-table @selection-change="handleSelectionChange" :row-key="getRowKey"    :data="gridData"   v-loading="state.loading" border :cell-style="tableStyle.cellStyle"
            :header-cell-style="tableStyle.headerCellStyle"  @sort-change="sortChangeHandle">
                <el-table-column type="selection" width="70" :reserve-selection="true"/>
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column prop="dataName" label="资料名称"/>
                <el-table-column prop="studyGroupId" label="参与组织" :show-overflow-tooltip="true"  :formatter="formatter"/>
                <el-table-column prop="studyPost" label="参与岗位" :show-overflow-tooltip="true"/>
                <el-table-column prop="majorNames" label="专业名称"  :formatter="formatter1"/>
                <el-table-column prop="keyPoint" label="关键点" :show-overflow-tooltip="true"/>
                <el-table-column prop="dataType" label="资料类型"/>
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-button  text type="primary" @click="handleTest(scope.row)">试题数量</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="avue-crud__pagination">
                <el-pagination @size-change="sizeChangeHandle1" @current-change="currentChangeHandle1" :current-page="pageIndex1"
                :page-sizes="[10, 20, 50, 100]" :page-size="pageSize1" :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
            <span style="font-weight:700">已选资料</span>
            <el-button type="primary" @click="sortTableData" style="margin-left: 10px">排序</el-button>
            <el-table  border  :data="targetTableData" style="margin-top: 20px;" align="center" >
                <el-table-column type="index" label="序号" width="60" align="center"/>
                <el-table-column prop="dataName" label="资料名称" align="center"/>
                <el-table-column prop="studyGroup" label="参与组织" width="300" :show-overflow-tooltip="true" align="center"/>
                <el-table-column prop="studyPost" label="参与岗位" align="center"/>
                <el-table-column prop="majorNames" label="专业名称" align="center"/>
                <el-table-column prop="keyPoint" label="关键点" align="center"/>
                <el-table-column prop="dataType" label="资料类型" align="center"/>
                <el-table-column label="可输入排序号" align="center">
                    <template #default="{ row, $index }">
                        <el-input v-model="row.score"  type="number" @change="handleScoreChange(row, $index)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-button text type="primary" @click="handleTest(scope.row)">试题数量</el-button>
                        <el-button type="text"  circle @click="handleDelete1(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" :visible.sync="dialogVisible" @click="onSubmit1" >确定</el-button>
                </div>
            </template>
        </el-dialog>
        <!-- 相关试题  -->
        <el-dialog v-model="dialogVisible1" :title="fileName+'--'+'试题数量'" width="20%">
            <el-table :data="testList" style="width: 72%;margin-left: 40px;font-size: 18px" border>
                <el-table-column prop="questionType" label="题型" show-overflow-tooltip>
                    <template #default="scope">
                        <dict-tag :options="tkgl_topic_type" :value="scope.row.questionType"></dict-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="count" label="题数(道)" width="120" align="center"/>
            </el-table>
        </el-dialog>
    </div>
</template>

<script setup lang="ts" name="systemKszlFile">
	//导入
    import { useDict } from '/@/hooks/dict';
    import { rule } from '/@/utils/validate';
    import { useRoute } from 'vue-router';
    import { defineEmits, reactive, ref ,onMounted } from 'vue';
    import { Action, ElMessage, ElMessageBox } from 'element-plus';
    import { useRouter } from 'vue-router';
	import { BasicTableProps, useTable } from "/@/hooks/table";
	import { useMessage, useMessageBox } from "/@/hooks/message";
    import { Session } from '/@/utils/storage';
	import mittBus from '/@/utils/mitt';
	import { fetchList, delObjs, putObj, office, officeView, } from '/@/api/train/kszlFile';
	import {keypointsList} from "/@/api/train/jnglKeyPoints";
	import { deptTree, getEditList, syspost, informationList, getTestList } from '/@/api/train/kszlData';
	import {getLevel, professionalnameList} from "/@/api/train/jnglProfessionLevel";
	import {saveProfession} from "/@/api/train/kszlFile"
    import { getKeyPointListByZymcIds, getUsers } from '/@/api/train/ksglExamList';
	import { createTask, detailsList, putObjsty, replace, deleteList, check, examdetailsList, score, examinationList, sededitList,certificatename } from '/@/api/train/xxrwTaskList';
	// 引入组件
	const FormDialog = defineAsyncComponent(() => import('./form.vue'));
    const cascaderAddr = ref<InstanceType<typeof import('element-plus/es/components/cascader')>>(null);
    const cascaderAddr1 = ref<InstanceType<typeof import('element-plus/es/components/cascader')>>(null);
	// 定义查询字典
    const { tkgl_topic_type } = useDict('tkgl_topic_type')
    const emit = defineEmits(['refresh']);
    const started = ref(false);
    const passMark = ref();
    const flag = ref(0)
    const isShow = ref(true)
    const persons1 = ref()
    const persons2 = ref()
    const namelist = ref()
    const dataFormRef1 = ref();
    const visible = ref(false)
    const loading = ref(false)
    const innerVisible = ref(false)
      // 缓存当前选中节点的key
    const cacheNodeKey = ref("");
      // 缓存拼接后的文本
    const cacheJoinLabel = ref("");
      //部门主键
    const durationInMinutes = ref()
      //学习岗位
    const formquerlist = reactive({
        isRelateExam:'',
        taskId:'',
        examId: '',
        examName: ''
      })
    const form1 = reactive({
        id:'',
        groupIds:[],
        examName: '',
        postIds:[],
		postNames:[],
        // examLabel: '',
        // adminName: '',
        examPaperName: '',
        examPaperId:'',
        groupNames: '',
        persons1:[{}],
        personName:'',
        examTime:'30',
        xxrwTranscriptEntityList:[],
        levelEntityList1:[],
        examRemark: '',
        // submitOntimeState: true,
        submitInadvanceState: 1,
        allowStartTime: '15',
        allowEndTime: '10',
        wrongQuestionFirstState: 0,
        sendRemindTime: '20',
        questionOrder: 1,
        optionsOrder: 1,
        finishExamState: 1,
        selectGradesState: 2,
        remark: '',
        posts:[],
    });
	//新增
    const dataFormRef =ref()
    const pointsformlist = ref();
	const examId = ref()
    const examInfoId = ref()
    const examPaperId = ref()
    // 定义变量内容
	const formDialogRef = ref()
	const groupId = ref()
	const groupIds = ref([])
	const orgId = ref([])
	const groupNames = ref([])
    const processedPKPosts = ref([])
    const personList = reactive([])
    const concatenatedNames =ref([])
    const pkPosts = ref([])
	const persons = ref(null)
	// 搜索变量
	const queryRef = ref()
	const showSearch = ref(true)
	// 多选变量
    const leftBoundary0 = ref()
    const leftBoundary1 = ref()
    const leftBoundary2 = ref()
    const leftBoundary3 = ref()
    const rightBoundary0 = ref()
    const rightBoundary1 = ref()
    const rightBoundary2 = ref()
    const rightBoundary3 = ref()
    const scoreLevel0 = ref()
    const scoreLevel1 = ref()
    const scoreLevel2 = ref()
    const scoreLevel3 = ref()
	const selectObjs = ref([]) as any
	const multiple = ref(true)
    const isOrgSelected = ref(false);
    const isPostSelected = ref(false);
    const isMajorSelected = ref(false);
    const hasKeyPointsSelected = ref(false)
    //弹框显示
	const testList =reactive([{}])
	const dialogVisible = ref(false)
	const dialogVisible1 = ref(false)
    const dialogVisible2 = ref(false)
	const isSwitchDisabled= ref(true) // 默认置灰，即禁用状态
	const isButtonDisabled= ref(false)// 默认禁用按钮
	const centerDialogVisible = ref(false)
    const targetTableData = ref([]); // 目标表格数据，初始为空
    const multipleSelection = ref([]); // 存储选中的行数据
    const xxrwTaskRelateDateList = ref([]) ;//表格回显
    const fileName = ref()
    const scoreList = reactive([])
	const state: BasicTableProps = reactive<BasicTableProps>({
		queryForm: {},
		pageList: fetchList
	})
    const concatenatedName =ref('')
    const certificateList =reactive([{
        certificateId: '',
        certificate: ''
    }])
	// 表单元素
	const dom = ref()
	const studyGroup = ref()
	// 校验规则
	const rules = ref({
		name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
	})
	// // 绑定数据
	const form = reactive({
        persons:[{}],
        posts:[],
		orgId:[],
		id:'',
		orgName:[],
		keyPoints:'',
        examName:'',
		examId:'',
		postId:[],
		postName:'',
		personInfo:[{}],
		taskName:'',
		isTimeLimit:0,
        taskState:1,
        endTime: '',
        startTime: new Date(),
        // startTime:'',
        totalDuration: '',
        isTopicEnd:1,
        isRelateExam:0,
        abnormalDays:'1',
        isExcutePlan:1,
        isExamAfterData: 1,
        isTopicEndAnswer: 1,
        zymcId: [],
        zymcName: [],
        keyId: [],
        keyPoint: [],
        //  证书字段
        gainCertificateIsStudy: 0,
        isIssuingCertificates: 0,
        certificateId: '',
        certificate: '',
        issuanceConditions: 1,
        issuanceConditionsProgress1: 60,
        issuanceConditionsProgress2:50,
        issuanceConditionsScore2: 60,
        issuanceConditionsScore3: 50,
        xxrwTaskRelateDateList:[],
		dataQuantity:'',
    })
    const route = useRoute();
	//新增弹框表单
	let keypointsform = reactive({
		keyId: "",
		zymcId: "",
		zydjId: "",
		keyPoint: "",
		remark: "",
		zymcName: "",
		zydjName: ""
	})
	const queryForm = reactive({
		studyGroup:'',
		studyPostIds:'',
		majorNameIds:'',
		keyPointIds:'',
		studyPost:'',
		majorNames:'',
		keyPoint:''
	})
	//  table hook
	const {
		getDataList,
		currentChangeHandle,
		sizeChangeHandle,
		sortChangeHandle,
		downBlobFile,
		tableStyle
	} = useTable(state)
	//返回上一页
	const router = useRouter();
	const isDisabled = ref(route.query.state === '1');
	const goBack = () => {
		router.push('/train/xxrwTaskList/index');
	};
    const formatter = (row:any) =>{
        return  row.studyGroup
    }
    const formatter1 = (row:any) =>{
        return  row.majorName
    }
    const checked = ref(false)
    const gridData = ref<any[]>([]); // 根据你的数据结构来定义类型
    const totalPage = ref(0);
    const pageIndex1 = ref(1); // 假设第一页是1
    const pageSize1 = ref(5); // 假设每页显
	//学习组织数据
	const options1 = ref<any[]>([]);
	//专业名称数据
	const options2 =reactive([{}])
    const changeMark =(val:any)=>{
        scoreList[1].leftBoundary = val
        form.passingScore =  val
        scoreList[0].rightBoundary = val
        rightBoundary0.value = val
    }
    const changeMark1 =(val:any)=>{
        scoreList[2].leftBoundary = val
        scoreList[1].rightBoundary = val
        rightBoundary1.value = val
    }
    const changeMark2 =(val:any)=>{
        scoreList[3].leftBoundary = val
        scoreList[2].rightBoundary = val
        rightBoundary2.value = val
    }
    const newPerson = ref([])
	//fileTableList
	const fileTableList = reactive([{}])
	//专业等级
	const zydjnamelist = reactive([{}])
	//学习岗位
	const postList =reactive([])
	//关键点
	const keypointsListData = reactive([{}])
	//部门主键
	const pkDept = ref()
    const menuItems = ref([]);
    const draggingRow = ref(null);
	const namesString = ref([])
	const editList = reactive([{}])
    const dataRules = ref({
		taskName: [{required: true, message: '任务名称不能为空', trigger: 'blur'}],
        orgId: [{required: true, message: '参考组织不能为空', trigger: 'blur'}],
        postName: [{required: true, message: '参考岗位不能为空', trigger: 'blur'}],
        persons: [{required: true, message: '参考人员不能为空', trigger: 'blur'}],
        personName: [{required: true, message: '参考人员不能为空', trigger: 'blur'}],
        zymcName: [{required: true, message: '专业名称不能为空', trigger: 'blur'}],
        keyPoint: [{required: true, message: '关键点不能为空', trigger: 'blur'}],
        // startTime: [{required: true, message: '开始时间不能为空', trigger: 'blur'}],
        // endTime: [{required: true, message: '结束时间不能为空', trigger: 'blur'}],
		startTime: [{ validator: (rule, value, callback) => {
              if (!value) {
                    return callback(new Error('请选择开始时间'));
                }
                const currentTime = new Date().getTime();
                const selectedTime = new Date(value).getTime();
                if (selectedTime <= currentTime) {
                    return callback(new Error('开始时间必须大于当前时间'));
                }callback();}, trigger: 'change',
        }],
        endTime: [{ validator: (rule, value, callback) => {
            if (!value) {
                return callback(new Error('请选择结束时间'));}
                const startTime = new Date(form.startTime).getTime();
                const selectedEndTime = new Date(value).getTime();
                const minEndTime = startTime + 30 * 60 * 1000; // 30分钟后的时间戳
                if (selectedEndTime <= minEndTime) {
                    return callback(new Error('结束时间必须大于开始时间30分钟以上'));
                }callback();}, trigger: 'change',
        }],
        abnormalDays: [{required: true, message: '异常提醒天数不能为空', trigger: 'blur'}],
    })
    // 定义校验规则
    const dataRules1 = ref({
        examName: [{required: true, message: '考试名称不能为空', trigger: 'blur'}],
        examLabel: [{required: true, message: '考试标签不能为空', trigger: 'blur'}],
        adminGroupId: [{required: true, message: '管理员组织不能为空', trigger: 'blur'}],
        adminName: [{required: true, message: '管理员姓名不能为空', trigger: 'blur'}],
        adminUserName: [{required: true, message: '管理员工号不能为空', trigger: 'blur'}],
        examPaperName: [{required: true, message: '试卷名称不能为空', trigger: 'blur'}],
        groupId: [{required: true, message: '考试组织名称不能为空', trigger: 'blur'}],
        postId: [{required: true, message: '参考岗位名称不能为空', trigger: 'blur'}],
        examType: [{required: true, message: '考试类型不能为空', trigger: 'blur'}],
        persons1: [{required: true, message: '参与人员不能为空', trigger: 'blur'}],
        submitOntimeState: [{required: true, message: '定时交卷不能为空', trigger: 'blur'}],
        submitInadvanceState: [{required: true, message: '提前交卷不能为空', trigger: 'blur'}],
        electronicInvigilationState: [{required: true, message: '电子监考不能为空', trigger: 'blur'}],
        allowMakeupExamState: [{required: true, message: '是否允许补考不能为空', trigger: 'blur'}],
        // allowStartTime: [{required: true, message: '考试开始后的时间不能为空', trigger: 'blur'}],
        cutscreenTimes: [{required: true, message: '允许切屏次数不能为空', trigger: 'blur'}],
        examTime: [{required: true, message: '考试时长不能为空', trigger: 'blur'}],
        sendRemindTime: [{required: true, message: '考试结束前不能为空', trigger: 'blur'}],
        questionOrder: [{required: true, message: '试题顺序不能为空', trigger: 'blur'}],
        optionsOrder: [{required: true, message: '选项顺序不能为空', trigger: 'blur'}],
        examTimeState: [{required: true, message: '考试状态不能为空', trigger: 'blur'}],
        finishExamState: [{required: true, message: '结束页面不能为空', trigger: 'blur'}],
        selectGradesState: [{required: true, message: '查询不能为空', trigger: 'blur'}],
        allowEndTime: [{required: true, message: '考试结束前的时间不能为空', trigger: 'blur'}],
    })
	const dataList = reactive([{}])
	//挂载完毕
	onMounted(()=>{
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以要加1
        const date = String(now.getDate()).padStart(2, '0');
        const hours = String(now.getHours()).padStart(2, '0');
        const minutes = String(now.getMinutes()).padStart(2, '0');
        const seconds = String(now.getSeconds()).padStart(2, '0');
        const delayInMinutes = 10;
        const delayInMilliseconds = delayInMinutes * 60 * 1000;
        const defaultStartTimeObj = new Date(now.getTime() + delayInMilliseconds); // 计算默认开始时间对象
        const defaultYear = defaultStartTimeObj.getFullYear();
        const defaultMonth = String(defaultStartTimeObj.getMonth() + 1).padStart(2, '0');
        const defaultDate = String(defaultStartTimeObj.getDate()).padStart(2, '0');
        const defaultHours = String(defaultStartTimeObj.getHours()).padStart(2, '0');
        const defaultMinutes = String(defaultStartTimeObj.getMinutes()).padStart(2, '0');
        const defaultSeconds = String(defaultStartTimeObj.getSeconds()).padStart(2, '0');
        const defaultStartTimeStr = `${defaultYear}-${defaultMonth}-${defaultDate} ${defaultHours}:${defaultMinutes}:${defaultSeconds}`;
        console.log(defaultStartTimeStr); // 输出格式化后的默认开始时间字符串
        form.startTime = defaultStartTimeStr
        console.log(form.startTime,'form.startTime');
        // 绑定事件
        mittBus.on('sendData',(value:any)=>{
            console.log('sendData事件被触发',value)
            const id = value
            if(id){
                getEditList(23).then((res)=>{
                    console.log('sendId111111',res)
                })
            }else {
            }
        })
        if(route.query.state =='1'){

        	// 编辑
            const taskId = route.query.taskId
            detailsList(taskId).then((res)=>{
                Object.assign(dataList, res.data)
                form.id = dataList.id
				console.log(form.id,dataList.id,'编辑id值');
                form.taskName = dataList.taskName
                const partOrgArray = dataList.orgId.split('/');
                form.orgId = partOrgArray
                console.log(form.orgId,partOrgArray,'编辑');
                form.orgName = dataList.orgName.split('/')
                // form.orgId = dataList.orgId
                persons.value = dataList.userList
                form.postName = dataList.postName
                form.zymcName = dataList.zymcName
				form.zymcId = dataList.zymcId
                form.keyPoint = dataList.keyPoint
                form.keyId = dataList.keyId
                form.postId = dataList.postId
                isOrgSelected.value = form.orgId !== null && form.orgId !== undefined && form.orgId!== '';
                isPostSelected.value = form.postName && form.postName.length > 0;
                isMajorSelected.value = form.zymcName &&  form.zymcName.length > 0;
                hasKeyPointsSelected.value = form.keyPoint && form.keyPoint.length > 0;
                form.startTime = dataList.startTime
                form.endTime = dataList.endTime
                form.abnormalDays = dataList.abnormalDays
                form.isTimeLimit = dataList.isTimeLimit
                form.isRelateExam = dataList.isRelateExam
                form.isExamAfterData = dataList.isExamAfterData
                form.isTopicEndAnswer = dataList.isTopicEndAnswer
                form.isTopicEnd = dataList.isTopicEnd
                form.isExcutePlan = dataList.isExcutePlan
				form.personInfo = dataList.personInfo
				form.examName = dataList.examName
                form.examId = dataList.examId
				form.isIssuingCertificates = dataList.isIssuingCertificates
				form.gainCertificateIsStudy = dataList.gainCertificateIsStudy
				form.certificate = dataList.certificate // 证书名称
                form.certificateId = dataList.certificateId
				form.issuanceConditions = dataList.issuanceConditions
                form.issuanceConditionsProgress1 = dataList.issuanceConditionsProgress1
                form.issuanceConditionsProgress2 = dataList.issuanceConditionsProgress2
                form.issuanceConditionsScore2 = dataList.issuanceConditionsScore2
				form.issuanceConditionsScore3 = dataList.issuanceConditionsScore3
                form.xxrwTaskRelateDateList = dataList.xxrwTaskRelateDateList.map(item => {
                return {
                    dataName : item.dataName,
					dataId:item.dataId,
                    studyGroup : item.groupName,
                    postName : item.postName,
                    zymcName : item.zymcName,
					zymcId : item.zymcId,
                    zydjId : item.zydjId,
                    zydjName : item.zydjName,
					keyId : item.keyId,
					totalDuration : item.totalDuration,
                    keyPoints : item.keyPoints,
                    dataType : item.dataType,
					groupId : item.groupId
                };
                });
                targetTableData.value = dataList.xxrwTaskRelateDateList.map(item => {
                return {
                      dataName : item.dataName,
                      dataId:item.dataId,
                      studyGroup : item.groupName,
                      studyPost : item.postName,
                      majorNames : item.zymcName,
                      keyPoint : item.keyPoints,
                      dataType : item.dataType,
                      zymcId : item.zymcId,
                      zydjId : item.zydjId,
                      zydjName : item.zydjName,
                      keyId : item.keyId,
                      totalDuration : item.totalDuration,
                      groupId : item.groupId,
                      majorNameId : item.zymcId,
                      keyPointId : item.keyId,
                      dataLevel: item.zydjName,
                      dataLevelId : item.zydjId,
                      minTime : item.totalDuration,
                      studyPostId : item.postId,
                      studyGroupId: item.groupId.join('/'),
                };
                });
                // 组卷id
                const examInfoId = dataList.examPaperId
                const examId = dataList.examId
            });
            }
            else{
				// form.examName = send
                // form.examId = form.examId
				// console.log(form.examName,form1.examName,'考试名称');
				// console.log(form.examId,form.examId,'考试id');
            }
            office().then((res)=>{})
            officeView().then((res)=>{})
            deptTreeList()
            getProfessionalName()
			getKeypointsList()
            setDefaultEndTime()
			certificatename()
    })
    //人员全选
    const selectAll=() =>{
        if (checked.value) {
            persons.value = personList.map(person => person.username);
            form.persons.length = 0
            concatenatedNames.value = [];
            personList.forEach(item =>{
                for (let i = 0; i < persons.value.length; i++) {
                    if (item.username == persons.value[i]) {
                        const newPerson = {
                            personName: item.name,
                            postId: item.pkPost,
                            userName: item.username,
                            postName: item.postName,
                            pkPsndoc: item.pkPsndoc,
                            groupId:groupIds.value,
                            groupName:groupNames.value,
                        };
                        form.persons.push(newPerson);
                        const concatenatedName = item.name + '-' + item.postName;
                        concatenatedNames.value.push(concatenatedName); // 将 concatenatedName 添加到数组中
                    }
                }
            })
        }else {
            persons.value = [];
            form.persons = [];
            concatenatedNames.value = [];
        }
    }
    const selectAll1=() =>{
        if (checked.value) {
            persons1.value = personList.map(person => person.username);
            form.persons1.length = 0
            personList.forEach(item =>{
                for (let i = 0; i < persons1.value.length; i++) {
                    if (item.username == persons1.value[i]) {
                        form.persons1.push({
                            personName:item.name,
                            postId:item.pkPost,
                            userName:item.username,
                            postName:item.postName,
                            pkPsndoc:item.pkPsndoc,
                            groupId:form.groupIds,
                            groupName:form.groupNames,
                        })
                    }
                }
            })
        }else {
            persons1.value.length = 0
            form.persons1.length = 0
        }
    }
    watch(persons, (newValue, oldValue) => {
        if (newValue.length === personList.length) {
            // 如果 persons 中的项数和 personList 中的项数相同，说明所有项都被选中了
            checked.value = true;
        } else if (newValue.length === 0) {
            // 如果没有任何项被选中，取消全选
            checked.value = false;
        } else {
            // 如果部分项被选中，取消全选
            checked.value = false;
        }
    });
    watch(() => route.query.state, (newVal) => {
            isDisabled.value = newVal === '1';}, { immediate: true });
	//时间格式转换
    const handleEndTimeChange = (val) => {
        if (!(val instanceof Date)) {
            console.error('val is not a Date object');
            return;
        }
        // 提取日期和时间的各个部分
        const year = val.getFullYear();
        const month = String(val.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1，并且使用padStart填充前导零
        const date = String(val.getDate()).padStart(2, '0'); // 使用padStart填充前导零
        const hours = String(val.getHours()).padStart(2, '0'); // 使用padStart填充前导零
        const minutes = String(val.getMinutes()).padStart(2, '0'); // 使用padStart填充前导零
        const seconds = String(val.getSeconds()).padStart(2, '0'); // 使用padStart填充前导零

        // 拼接成你想要的格式
        const formattedTime = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;

        // 设置 form.startTime 为格式化后的时间字符串
        form.startTime = formattedTime;

        // 打印结果
        console.log(form.startTime, 'shhsshs');
    // 	form.startTime = val;
    // console.log(form.startTime,val,'shhsshs');
    };

  // 证书改变触发change
  const changeexam = () => {
    if(form.isRelateExam == 1) {
      form.issuanceConditions = 3
    } else {
      form.issuanceConditions = 1
    }
  }
  const handleEndTimeChange1 = (value) => {
        // 当 endTime 改变时，格式化并打印或做其他处理
        const date = new Date(value);
        const formattedEndTime = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).slice(-2)}-${('0' + date.getDate()).slice(-2)} ${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
        form.endTime = formattedEndTime
        console.log(formattedEndTime, '输出121'); // 输出格式化后的时间
    };
    const formatDate = (date) => {
        return `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).slice(-2)}-${('0' + date.getDate()).slice(-2)} ${('0' + date.getHours()).slice(-2)}:${('0' + date.getMinutes()).slice(-2)}:${('0' + date.getSeconds()).slice(-2)}`;
    }
    const setDefaultEndTime = () => {
        const now = new Date();
        now.setHours(23, 59, 59, 59); // 设置时间为 23:59:00.000
        form.endTime = formatDate(now); // 将日期对象转换为字符串并赋值给 form.endTime
        console.log(form.endTime, 'ee');
    };
    // 提交已选资料
	const onSubmit1 = () =>{
		form.xxrwTaskRelateDateList = targetTableData.value.map((item) => {
      return {
        dataId: item.dataId,// 资料id
        dataName: item.dataName, // 资料名
        studyGroup: item.studyGroup,//组织名称
        postId: item.studyPostId, // 岗位id
        postName: item.studyPost, // 岗位名称
        zymcId: item.majorNameId, // 专业名称id
        zymcName: item.majorNames, // 专业名称
        keyId: item.keyPointId, // 关键点id
        keyPoints: item.keyPoint, // 关键点
        zydjName: item.dataLevel,//专业等级
        zydjId: item.dataLevelId,//专业等级id
        dataType: item.dataType,//资料类型
        totalDuration: item.minTime, // 时长
        groupId: item.studyGroupId.split('/'),
        //组织id
        // ...其他需要的字段映射
      }
    });
        form.dataQuantity = form.xxrwTaskRelateDateList.length;
        dialogVisible.value = false;
        // 在控制台打印选中的数据
        console.log(form.xxrwTaskRelateDateList,'xxrwTaskRelateDateList');
		console.log(form.dataQuantity,'总条数');
	}
	// 参与组织2
	const deptTreeList = () => {
		deptTree().then((res) => {
			options1.value = res.data;
			// console.log('111、、、',options1.value)
		});
	};
	const getItem1=(val:any) =>{
		let pkPosts = [];
        form.posts.length = 0
        personList.length = 0
        form.persons.length = 0
        persons.value.length =0
        // postList.length = 0
        postList.forEach(item => {
            for (let i = 0; i < val.length; i++) {
                if (item.postName == val[i]) {
                    pkPosts.push(item.postsString)
                    form.posts.push(item)
                }
            }
        })
        processedPKPosts.value.length=0
        pkPosts.forEach(item=>{
            if (item.includes(',')) {
                // 如果项包含逗号，则按逗号拆分
                const splitItems = item.split(',');
                splitItems.forEach(splitItem=>{
                    processedPKPosts.value.push(splitItem.trim())
                })
            }else {
                processedPKPosts.value.push(item)
            }
        })
        console.log('岗位', processedPKPosts.value)
        isPostSelected.value = processedPKPosts.value && processedPKPosts.value.length > 0;
        // 使用map将数组中的每个元素转换为URL参数形式，并用join连接它们
        const params = processedPKPosts.value.map((id, index) => {
            // 注意：这里index > 0时添加'&'，因为第一个元素前不需要
            return index > 0 ? '&pkPosts=' + id : 'pkPosts=' + id;
        }).join('');
        console.log('params',params)
        getUsers(params).then((res=>{
            Object.assign(personList,res)
            checked.value = true
            selectAll()
        }))
    }
	//	组织
    const handleCascaderChange1 = async (item: any) => {
        if(item!==null) {
          state.queryForm.groupId = item.join('/')
          groupId.value = item[item.length - 1];
          console.log(groupId.value,888888888)
          groupIds.value = item;
          if (cascaderAddr1.value) {
            groupNames.value = cascaderAddr1.value.getCheckedNodes()[0].pathLabels;
          }
          form.orgId = groupIds.value;
          form.orgName = groupNames.value;
          isOrgSelected.value = groupIds.value !== null && groupIds.value !== undefined && groupIds.value!== '';
          console.log('组织', form.orgName,form.orgId);
          form.postName = [];
          const originalValue = [groupId.value];
          console.log(originalValue,'originalValue');
          // getPostList1();
          // 编辑
          if (route.query.state === '1') {
            const examInfoId = dataList.examPaperId;
            const examId = dataList.examId
            // 根据examInfoId的值来决定是否弹出确认框
            if (examInfoId !== undefined && examInfoId !== null && examInfoId !== '') {
              // 弹出确认框，并等待用户的选择
              const confirmResult = await ElMessageBox.confirm('重新选择该组织,组织下已存在试题将进行清空,是否继续该操作', '提示', {
                    distinguishCancelAndClose: true,
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                  }
              ).then(async () => {
                try{
                  const replaceResult = await replace(examInfoId);
                  console.log('用户点击了确定', replaceResult.data);
                  useMessage().success('该组织涉及到的试题已清空');
                  const response2 = await deleteList(examId);
                  console.log('用户点击了确定222', response2.data);
                }catch (error) {
                  // 接口调用失败的处理逻辑
                  console.error('接口调用失败:', error);
                  useMessage().error('接口调用失败，请重试');
                }
              }).catch((action: Action) => {
                let partOrgArray = dataList.orgId.split('/');
                form.orgId = partOrgArray
                console.log('groupId 和 groupIds 已重置:',form.orgId);
              })

            } else {
              console.log('examInfoId 为空，不弹出确认框');
              // 在这里可以执行其他逻辑，比如直接处理或不做任何操作
            }
          } else {
            // // 非编辑
            const examPaperId =	route.query.examPaperId
            if (examPaperId !== undefined && examPaperId !== null && examPaperId !== '') {
              // 弹出确认框，并等待用户的选择
              const confirmResult = await ElMessageBox.confirm('重新选择该组织,组织下已存在试题将进行清空,是否继续该操作', '提示', {
                distinguishCancelAndClose: true,
                confirmButtonText: '确认',
                cancelButtonText: '取消',
              }).then(async () => {
                try{
                  const replaceResult = await replace(examPaperId);
                  console.log('用户点击了确定', replaceResult.data);
                  useMessage().success('该组织涉及到的试题已清空');
                }catch (error) {
                  // 接口调用失败的处理逻辑
                  console.error('接口调用失败:', error);
                  useMessage().error('接口调用失败，请重试');
                }
              }).catch((action: Action) => {
                form.orgId = route.query.groupIds1
                console.log('已重置:',form.orgId);
              })
            } else {
              //    // examInfoId为空，不执行弹窗逻辑
              console.log('examInfoId 为空，不弹出确认框');
              // 在这里可以执行其他逻辑，比如直接处理或不做任何操作
            }
          }
        } else {
          state.queryForm.studyPosts = []
          state.queryForm.postNames = []
        }
		};
    const getItem2=(val:any) =>{
        form.persons.length = 0
			concatenatedNames.value = [];
			personList.forEach(item =>{
            for (let i = 0; i < val.length; i++) {
                if (item.username == val[i]) {
                    const newPerson = {
                        personName: item.name,
                        postId: item.pkPost,
                        userName: item.username,
                        postName: item.postName,
                        pkPsndoc: item.pkPsndoc,
                        groupId: form.orgId,
                        groupName: form.orgName,
                    };
                    form.persons.push(newPerson);
					console.log('、、、',newPerson)
                    const concatenatedName = item.name + '-' + item.postName;
                    concatenatedNames.value.push(concatenatedName); // 将 concatenatedName 添加到数组中
                }
            }
        })
			getKeypointsList()
    }
    //专业名称
    const  getProfessionalName = () => {
        professionalnameList().then((res) => {
            Object.assign(options2, res.data)
        });
    };
    // 专业名称  --------------测试
    const getitem3 = (val : any) =>{
        form.zymcId = []; // 存储选中项的zymcId数组
        const zymcName = val; // 这就是你通过v-model获取的zymcName数组
        // 遍历options2，找到与选中项匹配的zymcId
        options2.forEach(option => {
            if (zymcName.includes(option.zymcName)) {
                form.zymcId.push(option.zymcId);
            }
        });
        // 更新form中的majorName字段，如果你需要的话
        form.majorName = zymcName.join('/');
        form.keyId = []; // 重置keyPoint数组
        getKeypointsList();
        isMajorSelected.value = val && val.length > 0;
    }
    //关键点
    const  getKeypointsList = () =>{
        keypointsListData.length = 0
        const ids = {
            zymcIds:  form.zymcId
        }
        getKeyPointListByZymcIds(ids).then((res) => {
            Object.assign(keypointsListData, res.data)
        });
    }
    const getitem4 = (val :any) =>{
        form.keyId = []; // 获取keyId数组
        const keyPoint = val;
        keypointsListData.forEach(option => {
            if (keyPoint.includes(option.keyPoint)) {
                form.keyId.push(option.keyId);
            }
        });
        // 更新form中的majorName字段，如果你需要的话
        form.keyPoints = keyPoint.join('/');
		console.log(form.keyPoints);
        hasKeyPointsSelected.value = val && val.length > 0;
    }
    //参考组织下拉框关闭事件
    const handleVisibleChange = (isVisible:any) => {
      if(!isVisible) {
        if (cascaderAddr1.value) {
          const checkedNodes = cascaderAddr1.value.getCheckedNodes(); // 输出选中的节点信息
          groupId.value = checkedNodes[0].value
        }
        getPostList1()
      }
    };
    //学习岗位
    const getPostList1 =  () =>{
      postList.length = 0
        const num = groupId.value
      console.log(groupId.value)
      console.log(num)
        console.log('----',num,pkDept.value)
        syspost(num).then((res: any) => {
            Object.assign(postList, res.data)
            postList.forEach((item,index)=>{
                const postsArray = item.postsString.split(',');
            })
        });
    }
    //拿到树节点id
    const treeHandleChange = (value:any) => {
        // value为选中节点数据
        pkDept.value = value.id
        studyGroup.value = value.name
        getPostList()
    }
    //学习岗位
    const getPostList =  () =>{
        const num = pkDept.value
        syspost(num).then((res: any) => {
            Object.assign(postList, res.data)
        });
    }
	//修改表格单元格
	const changeHandle = (currentRow:any)=>{
		putObj(currentRow).then((res)=>{
		})
	}
    // 关联资料
    const association = async () => {
		dialogVisible.value = true;
        queryForm.studyPost = form.postName
        queryForm.majorNames = form.zymcName
        queryForm.keyPoint = form.keyPoint
        queryForm.majorNameIds = form.zymcId.join('，')
        queryForm.keyPointIds  = form.keyId.join('，')
        if(dataList.taskId == undefined || dataList.taskId == '' ||  dataList.taskId == null){
			queryForm.studyPostIds = processedPKPosts.value.join('，')
        }else{
			queryForm.studyPostIds = form.postId.join('，')
        }
        try {
        const response = await informationList({
            current: pageIndex1.value,
            size: pageSize1.value,
            studyPostIds: queryForm.studyPostIds, // 添加这个参数
            majorNameIds: queryForm.majorNameIds, // 添加这个参数
            keyPointIds: queryForm.keyPointIds, // 添加这个参数

        });
        totalPage.value = response.data.total;
        gridData.value = response.data.records
        } catch (error) {
            console.error('Error fetching data:', error);
        }
        queryList()
    }
    // 关联资料查询
    const queryList = async () => {
        queryForm.majorNameIds = form.zymcId.join(',')
        queryForm.keyPointIds  = form.keyId.join(',')
        if(dataList.taskId == undefined || dataList.taskId == '' ||  dataList.taskId == null){
            queryForm.studyPostIds = processedPKPosts.value.join(',')
        }else{
            queryForm.studyPostIds = form.postId.join(',')
        }
        try {
            const response = await informationList({
                current: pageIndex1.value,
                size: pageSize1.value,
                studyPostIds: queryForm.studyPostIds, // 添加这个参数
                majorNameIds: queryForm.majorNameIds, // 添加这个参数
                keyPointIds: queryForm.keyPointIds, // 添加这个参数

            });
            console.log(response, '关联资料');
            totalPage.value = response.data.total;
            gridData.value = response.data.records
            console.log('资料', gridData);
        } catch (error) {
            console.error('Error fetching data:', error);
        }
    }
    // 每页数
    const  sizeChangeHandle1 = (val:number)=> {
        pageSize1.value = val
        association()
    }
    // 当前页
    const  currentChangeHandle1 =(val:number)=> {
        pageIndex1.value = val
        association()
    }

    /*多选回显表格*/
    const handleSelectionChange = (val) => {
        const selectedRows = val.map((item) => ({
            dataName: item.dataName,//资料名称
            dataId: item.dataId,//资料id
            studyGroup: item.studyGroup,//组织名称
            studyGroupId: item.studyGroupId,//组织id
            studyPost: item.studyPost,//岗位名称
            studyPostId: item.studyPostId,//岗位id00000
            majorNames: item.majorName,//专业名称
            majorNameId: item.majorNameId,//专业名称id
            dataLevel: item.dataLevel,//专业等级
            dataLevelId: item.dataLevelId,//专业等级id
            keyPoint : item.keyPoint,//关键点
            keyPointId: item.keyPointId,//关键点id
            dataType: item.dataType,//资料类型
            minTime: item.minTime,//时长
            score: 1,
        }))
        const uniqueSelectedRows = selectedRows.filter(row => !targetTableData.value.some(existingRow => {
            return existingRow.dataId === row.dataId; // 假设 dataId 是唯一的标识符
        }));
        // 使用 concat 或者扩展运算符将选中项追加到 targetTableData 的末尾
        targetTableData.value = targetTableData.value.concat(uniqueSelectedRows);
		// targetTableData.value = selectedRows;
        console.log(targetTableData.value,'targetTableData.value');
		}
    const sortTableData = () => {
        targetTableData.value.sort((a, b) => a.score - b.score);
    };
    const getRowKey = (row: any, ) => {
        return row.dataId
        console.log(row.dataId,'row');
    }
    //相关试题
    const handleTest = (row:any) =>{
        fileName.value = row.dataName
        const id = row.dataId
        dialogVisible1.value = true
        testList.length = 0
        getTestList(id).then((res)=>{
            Object.assign(testList, res.data.data)
            // console.log('试题、、、',testList)
        })
    }
    const handleDelete1 = (index,row) => {
        // 确认删除操作
        if (window.confirm('确定删除吗？')) {
            // 使用 splice 方法从数组中删除对应的行
			targetTableData.value.splice(index, 1);
        }
    };
	// 删除操作
	const handleDelete = async (ids: string[]) => {
		try {
			await useMessageBox().confirm('此操作将永久删除');
		} catch {
			return;
		}
		try {
			await delObjs(ids);
			getDataList();
			useMessage().success('删除成功');
		} catch (err: any) {
			useMessage().error(err.msg);
		}
	};
    const hasSelectedData = computed(() => {
        return form.xxrwTaskRelateDateList.length > 0;
    });
    const pEmitData=(data:any)=>{
        if(data.id!==undefined){
            form1.examPaperId = data.id
            form1.examPaperName = data.name
            flag.value = 1
            isShow.value = true
        }else {
            form1.examPaperName = data.name
        }
    }
	const testquestions = async() =>{
			dialogVisible2.value = true;
			if(route.query.state =='1'){
        if(form.examId || form.examName) {
          scoreList.length = 0
          examdetailsList(form.examId).then((res) => {
            console.log(res.data,222222222222222)
            Object.assign(form1, res.data)
            form1.groupIds = form1.groupId.split(",")
            form1.groupNames = form1.groupName.split("/")
            form1.postNames = form1.postName.split(",")
            form1.postIds = form1.postId.split(",")
            form1.examPaperId = form1.examPaperId
            persons2.value = []
            form1.xxrwTranscriptEntityList.forEach(item => {
              let personName = item.personName
              persons2.value.push(personName)
            })
            console.log('persons2.value1111111111111111111111111',persons2.value)

            form1.questionOrder = form1.questionOrder
            getPostList()
            score(form.examId).then((res => {
              Object.assign(scoreList, res.data)
              leftBoundary0.value = scoreList[0].leftBoundary
              leftBoundary1.value = scoreList[1].leftBoundary
              leftBoundary2.value = scoreList[2].leftBoundary
              leftBoundary3.value = scoreList[3].leftBoundary
              rightBoundary0.value = scoreList[0].rightBoundary
              rightBoundary1.value = scoreList[1].rightBoundary
              rightBoundary2.value = scoreList[2].rightBoundary
              rightBoundary3.value = scoreList[3].rightBoundary
              scoreLevel0.value = scoreList[0].scoreLevel
              scoreLevel1.value = scoreList[1].scoreLevel
              scoreLevel2.value = scoreList[2].scoreLevel
              scoreLevel3.value = scoreList[3].scoreLevel
              passMark.value =  leftBoundary1.value
            }))
          })
          return
        }
				form.examId = dataList.examId
				// 编辑页面===新增考试
				if(form.examId == undefined || form.examId == null || form.examId == ''){
					let arr = [
						{id: 1, leftBoundary: 0, rightBoundary: 60, scoreLevel: "不及格",},
						{id: 2, leftBoundary: 60, rightBoundary: 80, scoreLevel: "及格",},
						{id: 3, leftBoundary: 80, rightBoundary: 100, scoreLevel: "优秀",},
						{id: 4, leftBoundary: 100, rightBoundary: 100, scoreLevel: "完美",}
					]
					Object.assign(scoreList,arr)
          console.log(333333333333333)
					leftBoundary0.value = scoreList[0].leftBoundary
					leftBoundary1.value = scoreList[1].leftBoundary
					leftBoundary2.value = scoreList[2].leftBoundary
					leftBoundary3.value = scoreList[3].leftBoundary
					rightBoundary0.value = scoreList[0].rightBoundary
					rightBoundary1.value = scoreList[1].rightBoundary
					rightBoundary2.value = scoreList[2].rightBoundary
					rightBoundary3.value = scoreList[3].rightBoundary
					scoreLevel0.value = scoreList[0].scoreLevel
					scoreLevel1.value = scoreList[1].scoreLevel
					scoreLevel2.value = scoreList[2].scoreLevel
					scoreLevel3.value = scoreList[3].scoreLevel
					passMark.value =  leftBoundary1.value
					form1.groupIds = dataList.orgId.split('/');
					form1.groupNames = dataList.orgName.split('/')
					form1.persons1 = dataList.personInfo;
					form1.postIds = dataList.postId
					form1.postNames = dataList.postName
					persons2.value = dataList.userList
          console.log('persons2.value',persons2.value)
				}else{
                    scoreList.length = 0
					// 正常编辑考试调用查询接口
					examdetailsList(form.examId).then((res) => {
            console.log(res.data,222222222222222)
						Object.assign(form1, res.data)
						form1.groupIds = form1.groupId.split(",")
						form1.groupNames = form1.groupName.split("/")
						form1.postNames = form1.postName.split(",")
						form1.postIds = form1.postId.split(",")
						form1.examPaperId = form1.examPaperId
                         persons2.value = []
						form1.xxrwTranscriptEntityList.forEach(item => {
							let personName = item.personName
							persons2.value.push(personName)
						})
                        console.log('persons2.value1111111111111111111111111',persons2.value)

                        form1.questionOrder = form1.questionOrder
						getPostList()
						score(form.examId).then((res => {
							Object.assign(scoreList, res.data)
							leftBoundary0.value = scoreList[0].leftBoundary
							leftBoundary1.value = scoreList[1].leftBoundary
							leftBoundary2.value = scoreList[2].leftBoundary
							leftBoundary3.value = scoreList[3].leftBoundary
							rightBoundary0.value = scoreList[0].rightBoundary
							rightBoundary1.value = scoreList[1].rightBoundary
							rightBoundary2.value = scoreList[2].rightBoundary
							rightBoundary3.value = scoreList[3].rightBoundary
							scoreLevel0.value = scoreList[0].scoreLevel
							scoreLevel1.value = scoreList[1].scoreLevel
							scoreLevel2.value = scoreList[2].scoreLevel
							scoreLevel3.value = scoreList[3].scoreLevel
							passMark.value =  leftBoundary1.value
						}))
					})
				}
			}
			else{
        if(form.examId || form.examName) {
          scoreList.length = 0
          examdetailsList(form.examId).then((res) => {
            console.log(res.data,222222222222222)
            Object.assign(form1, res.data)
            form1.groupIds = form1.groupId.split(",")
            form1.groupNames = form1.groupName.split("/")
            form1.postNames = form1.postName.split(",")
            form1.postIds = form1.postId.split(",")
            form1.examPaperId = form1.examPaperId
            persons2.value = []
            form1.xxrwTranscriptEntityList.forEach(item => {
              let personName = item.personName
              persons2.value.push(personName)
            })
            console.log('persons2.value1111111111111111111111111',persons2.value)

            form1.questionOrder = form1.questionOrder
            getPostList()
            score(form.examId).then((res => {
              Object.assign(scoreList, res.data)
              leftBoundary0.value = scoreList[0].leftBoundary
              leftBoundary1.value = scoreList[1].leftBoundary
              leftBoundary2.value = scoreList[2].leftBoundary
              leftBoundary3.value = scoreList[3].leftBoundary
              rightBoundary0.value = scoreList[0].rightBoundary
              rightBoundary1.value = scoreList[1].rightBoundary
              rightBoundary2.value = scoreList[2].rightBoundary
              rightBoundary3.value = scoreList[3].rightBoundary
              scoreLevel0.value = scoreList[0].scoreLevel
              scoreLevel1.value = scoreList[1].scoreLevel
              scoreLevel2.value = scoreList[2].scoreLevel
              scoreLevel3.value = scoreList[3].scoreLevel
              passMark.value =  leftBoundary1.value
            }))
          })
          return
        }
				// 新增学习任务-新增考试
				let arr = [
					{id: 1, leftBoundary: 0, rightBoundary: 60, scoreLevel: "不及格",},
					{id: 2, leftBoundary: 60, rightBoundary: 80, scoreLevel: "及格",},
					{id: 3, leftBoundary: 80, rightBoundary: 100, scoreLevel: "优秀",},
					{id: 4, leftBoundary: 100, rightBoundary: 100, scoreLevel: "完美",}
				]
				Object.assign(scoreList,arr)
				leftBoundary0.value = scoreList[0].leftBoundary
				leftBoundary1.value = scoreList[1].leftBoundary
				leftBoundary2.value = scoreList[2].leftBoundary
				leftBoundary3.value = scoreList[3].leftBoundary
				rightBoundary0.value = scoreList[0].rightBoundary
				rightBoundary1.value = scoreList[1].rightBoundary
				rightBoundary2.value = scoreList[2].rightBoundary
				rightBoundary3.value = scoreList[3].rightBoundary
				scoreLevel0.value = scoreList[0].scoreLevel
				scoreLevel1.value = scoreList[1].scoreLevel
				scoreLevel2.value = scoreList[2].scoreLevel
				scoreLevel3.value = scoreList[3].scoreLevel
				passMark.value =  leftBoundary1.value
				form1.groupIds = form.orgId
				form1.groupNames = form.orgName
				console.log(form1.groupIds,form1.groupNames,'新建考试');
				form1.persons1 = form.persons
				console.log(form1.persons1,'所有岗位');
				form1.postIds = processedPKPosts.value
				form1.postNames = form.postName
				console.log(form.postId,form1.postIds,'岗位id名称');
				persons2.value = persons.value
				console.log(persons2.value,'人员');
			}
		}
	//	证书名称
    certificatename().then((res) => {
        certificateList.length = 0;
        for (let index = 0; index < res.length; index++) {
            certificateList.push({
                certificate: res[index].certificateTemplateName,
                certificateId: res[index].certificateTemplateId,
            });
        }
        console.log("查询分类===>",certificateList);
    });
    // //保存考试
    const onSubmit = async () => {
        form1.levelEntityList1.length = 0
        // form1.persons = persons2.value
        if(route.query.state =='1'){
          form1.persons1 = form.personInfo
        } else {
          form1.persons1 = form.persons
          console.log(form.examId,111111111111111111)
        }
      const valid = await dataFormRef1.value.validate().catch(() => {});
      if(!valid) return false
        try {
            const taskId = dataList.taskId;
            const response = await check(taskId); // 校验接口
            const { code,msg } = response;
            form.examName = form1.examName
          console.log(scoreList,555555555555)
            if (code === 0) {
                scoreList.forEach(item => {
                    let obj = {
                        leftBoundary: item.leftBoundary,
                        rightBoundary: item.rightBoundary,
                        scoreLevel: item.scoreLevel,
                    }
                    form1.levelEntityList1.push(obj)
                })
              console.log(form,22222222222222222)
              console.log(form1,333333333333333333)
              form.examId = dataList.examId

              if (form.examId == undefined || form.examId == null || form.examId == '') {
                examinationList(form1).then((res => {
                  form.examId = res.data
                  form.examName = form1.examName
                  console.log('返回值',form.examId,form.examName);
                  ElMessage({
                    message: '创建成功',
                    type: 'success',
                  })
                })).catch(error => {
                  alert('创建失败');
                })
              } else {
                delete form1.xxrwTranscriptEntityList;
                sededitList(form1).then((res => {
                  ElMessage({
                    message: '修改成功',
                    type: 'success',
                  })
                })).catch(error => {
                  alert('修改失败');
                })
              }
                // dataFormRef1.value?.validate((valid: any) => {
                //     if (valid) {
                //
                //
                //
                //     }
                // })
                // loading.value = false;
                dialogVisible2.value = false;
            } else if (code === 1) {
                ElMessageBox({
                    message: msg,
                    type: 'error',
                });
            }
        } catch (error) {
            ElMessageBox({
                message: error.msg,
                type: 'error',
            });
        }finally {}
    }
    // 保存学习任务
    const uploadSysFileSubmit = () => {
      if(form.isRelateExam == 1) {
        console.log(1111111111111111111111111111111111111111111)
        if(form.examName.length == 0) {
          ElMessage.error('请选择关联考试')
          return
        }
      }
        form.taskId = dataList.taskId
        console.log('222',form.taskId);
        dataFormRef.value?.validate(valid => {
            if (valid) {
              isButtonDisabled.value = true
            // 新增操作
                if (form.taskId === undefined) {
                    form.orgId = groupIds.value.join('/');
                    form.orgName = groupNames.value.join('/');
                    form.personInfo = form.persons
                    form.postId = processedPKPosts.value
                    // form.enhshsh
                    if (!hasSelectedData.value) {
                        ElMessage({
                            message: '请至少选择一项学习资料!',
                            type: 'warning',
                        });
                        isButtonDisabled.value = false;
                        return; // 阻止保存逻辑继续执行
                    }
                    if (form.isIssuingCertificates === 1 && !form.certificateId) {
                        ElMessage({
                            message: '请选择证书名称!',
                            type: 'warning',
                        });
                        isButtonDisabled.value = false;
                        return; // 阻止保存逻辑继续执行
                    }
                    createTask(form).then(res => {
                        ElMessage({
                            message: '创建成功',
                            type: 'success',
                        });
                         isButtonDisabled.value = true;
                        const path = '/train/xxrwTaskList/index';
                        router.push(path);
                    }).catch(error => {
                        if (error && typeof error === 'object' && error.hasOwnProperty('msg')) {
                            // 显示具体的错误信息
                            ElMessage({
                                message: error.msg, // 使用接口返回的 msg
                                type: 'error', // 通常是错误类型
                            });
                        } else {
                            // 如果没有具体的 msg，则显示通用的错误信息
                            ElMessage({
                                message: '创建失败，请检查您的输入或联系管理员',
                                type: 'error',
                            });
                        }
                        console.error(error); // 仍然打印完整的错误对象到控制台，方便调试
                        isButtonDisabled.value = false; // 失败后启用按钮，以便用户可以重试
                    })
                } else {
                    // 修改操作
                  if (form.isIssuingCertificates === 1 && !form.certificateId) {
                    ElMessage({
                      message: '请选择证书名称!',
                      type: 'warning',
                    });
                    isButtonDisabled.value = false;
                    return; // 阻止保存逻辑继续执行
                  }
                    form.orgId = dataList.orgId;
                    form.orgName = dataList.orgName;
                    console.log(form.xxrwTaskRelateDateList,1111111111113232)
                    form.dataQuantity = form.xxrwTaskRelateDateList.length

                    //   if (dataList.dataQuantity == undefined || dataList.dataQuantity == '' ||  dataList.dataQuantity == null){
                    //     console.log(111111111111111111111111111111111111111)
                    //         form.dataQuantity = form.xxrwTaskRelateDateList.length;
                    //   }else{
                    //     console.log(2222222222222222222222222222222)
                    //         form.dataQuantity = dataList.dataQuantity
                    //   }
					          console.log(form.dataQuantity,'条数');
                    putObjsty(form).then(res => {
                        ElMessage({
                            message: '修改成功',
                            type: 'success',
                        });

						isButtonDisabled.value = true;
                        const path = '/train/xxrwTaskList/index';
                        router.push(path);
                    }).catch(error => {
                        if (error && typeof error === 'object' && error.hasOwnProperty('msg')) {
                            // 显示具体的错误信息
                            ElMessage({
                                message: error.msg, // 使用接口返回的 msg
                                type: 'error', // 通常是错误类型
                            });
                        } else {
                            // 如果没有具体的 msg，则显示通用的错误信息
                            ElMessage({
                                message: '创建失败，请检查您的输入或联系管理员',
                                type: 'error',
                            });
                        }
                        console.error(error); // 仍然打印完整的错误对象到控制台，方便调试
                        isButtonDisabled.value = false; // 失败后启用按钮，以便用户可以重试
                    })
                }
            } else {
                ElMessage({
                    message: '表单验证失败，请检查填写内容',
                    type: 'error',
                });
            }
        });
    };
</script>
<style lang="scss" scoped>
    .my-heading {
        color: black;
        font-weight: bold;
        font-size: 26px;
        margin-bottom: 10px;
    }
    .el-form{
        margin-left: 15px;
    }
    .select1{
        width: 50px;
    }
</style>



